import Vue from 'vue'
import App from './App.vue'

import VueRouter from 'vue-router'

Vue.use(VueRouter)

import VueResource from 'vue-resource'

Vue.use(VueResource)


// 1.创建组件
import Home from "./components/home.vue";
import News from "./components/news.vue";
import Detail from "./components/detail.vue";
import User from "./components/user.vue";
import UserAdd from "./components/user/userAdd.vue";
import UserList from "./components/user/userList.vue";

// 2.配置路由
const routers = [
  { path: '/home', component: Home },
  { path: '/news', component: News, name: "news" },//给路由起个名字
  { path: '/detail/:aid', component: Detail },//动态路由
  {
    path: '/user', component: User, name: "user",
    children: [
      { path: 'userAdd', component: UserAdd },
      { path: 'userList', component: UserList }
    ]
  }//动态路由
  // { path: '*', redirect: '/home' }   /*默认跳转路由*/
]

// 3.实例化VueRouter
const router = new VueRouter({
  //mode: "history",//默认的hash模式变成history模式，去掉url中乱七八糟的#等符号。
  // routes 
  //缩写，相当于routers: routers
  routes: routers
})

// 4. 挂载路由
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

// 5. <router-view></router-view> 放在App.vue里面（动态加载路由）
